//related to badgeround.ui
var root = ui("$");
var page = sm("do_Page");
var qqHttp = require("helper/http");
var httpSilence = require("helper/httpSilence");
var communityUrl = require("url/community");
var indexCacher = require("helper/indexCacher");
//遮罩显示
var animMaskShow = mm("do_Animator");
var propsMS = {bgColor:"00000044"};
animMaskShow.append(320,propsMS,"EaseOut");
//面板显示
var animPanelShow = mm("do_Animator");
var propsPS = {x:140,alpha:1};
animPanelShow.append(320,propsPS,"EaseOut");
//遮罩隐藏
var animMaskHide = mm("do_Animator");
var propsMH = {bgColor:"00000000"};
animMaskHide.append(320,propsMH,"EaseOut");
//面板隐藏
var animPanelHide = mm("do_Animator");
var propsPH = {x:640,alpha:0.8};
animPanelHide.append(320,propsPH,"EaseOut");
//遮罩
var bgmask = ui("maskbg");
var paneler = ui("topicMain"); //修改id
var panelerClose = function(){
	bgmask.animate(animMaskHide,function(){
		bgmask.visible = false;
	});
	paneler.animate(animPanelHide);
};
bgmask.on("touch","",300, panelerClose);
//显示
root.on("topicShow",function(data){
	bgmask.visible = true;
	bgmask.animate(animMaskShow);
	paneler.animate(animPanelShow);
	//事件
	topic.init();
});
root.on("topicClose",function(data){
	panelerClose();
});
ui("layoutBack").on("touch",function(data){
	panelerClose();
});
var hotView = ui("hotView");
var curText = ui("curText");
var topic = {
	hotData:[],
	init:function(_text){
		var _tagCacher = indexCacher.selectTagName();
		if(_tagCacher){
			curText.text = _tagCacher.name;
			curText.tag = _tagCacher.id;
		}
		else{
			curText.text = "全部话题";
			curText.tag = 0;
		}
		topic.getList();
	},
	getList:function(){//热门话题
		httpSilence.post(communityUrl.url.message.tagList, {}, function(data) {
			var _data = data.tagList;
			_data.unshift({id:0,name:"全部话题"});
			topic.hotData = _data;
			hotView.items= _data;
		})
	}
};

hotView.on("touch",function(data){
	panelerClose();
	page.fire("getHotList",{id:topic.hotData[data].id,name:topic.hotData[data].name});
})
ui("layoutCur").on("touch",function(data){
	panelerClose();
	page.fire("getHotList",{id:curText.tag,name:curText.text});
});
